<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<button>运算</button>
<button>假死</button>
<button>分线程执行</button>
</body>
<script>
    const btns = document.querySelectorAll("button");
    // 延迟一丁点
    btns[0].onclick = function () {
        let n = 0;
        for (let i = 0; i < 999999999; i++) {
            n += Math.random();
        }
        console.log("运算结束", n);
    }
    // 假死
    btns[1].onclick = function () {
        console.log("你点我了！")
    }
    btns[2].onclick = function(){
        if(window.Worker){
            // 指定在分线程中执行的文件
            const worker = new Worker("./lib/my.js");
            worker.postMessage(99999999);

        }else{
            console.log("不支持Worker")
        }
    }
</script>
</html>